{% extends 'base.html' %}
{% block title %}小鹿医馆{% endblock %}
{% block nav_title %}相似病历{% endblock %}

{% block css_and_js -%}
{{ super() }}
{#    <script src="http://cdn.bootcss.com/jquery/3.3.1/jquery.min.js"></script>#}
    <script src="{{ url_for('static', filename='js/jquery-3.3.1.js') }}"></script>
    <script src="{{ url_for('static', filename='js/exif.js') }}"></script>
    <script src="{{ url_for('static', filename='js/main.js') }}"></script>
    <script src="{{ url_for('static', filename='js/function_all.js') }}"></script>

    <style>
        body {text-align: left;}
        .row {margin-top: 1px; margin-bottom: 1px}
        [class|="col"] {padding-top: 10px; padding-bottom: 10px}
        .diag_title {font-size: 36px}
        .diag_content {font-size: 34px; padding-left: 30px}
        #file {
            position: absolute;
            left: 0;
            top: 0;
            opacity: 0;
            width: 100%;
            height: 100%;
        }
        @media screen and (min-width: 768px) {
            #border-right-col {border-right: 1px solid lightgray}
            #image {text-align:right}
            #diag {text-align: left}
        }
        @media screen and (max-width: 768px) {
            #diag .enter {display: none}
        }
    </style>
{% endblock %}



{% block content %} 
<div class="container">
    <div class="page-header"> 
		<body>
			<form>
                <img class="index-logo-src"  src="static/sy.png" alt="到小鹿首页" title="到小鹿首页">

				<input type="text" class="input" name="keyword" placeholder="请输入关键词"  id="text" style="width:500px; height:50px;">
				<input type="button"  value="搜索一下" id = 'btn' style="width:100px; height:50px;background-color: #1890ff" >
			</form>
            <!--<iframe name="my" style="display: none" frameborder="0"></iframe> target="my" -->
		</body>
	</div>
</div>

<style>
    .tableShow{
 white-space: nowrap;
}
</style>
<body>

<div id="head">
</div>
<div id="container">
</div>


<script type="text/javascript">

    $("#btn").click(function(){
        $.ajax({
            url:"/sp",
            type:"GET",
            data:{
                keyword:$("#text").val()
            }
        }).done(function(data){
            var res = JSON.parse(data);
            var keyword = $("#text").val();
            var text_usr_dict = res;
            keyword = keyword.replace(',',' ').replace('，',' ');

             console.log(keyword);
             if (keyword) {

                 //将数据显示出来--动态生成表格--相似患者

                 var table = "<table border=1 align='center'><th rowspan=\"2\">序号</th>";
                 table += "<th rowspan=\"2\" width=200>自述</th>";
                 table += "<th colspan=\"2\" width=600> 问诊单</th>";
                 table += " <th rowspan=\"2\">性别</th>";
                 table += " <th rowspan=\"2\">年龄</th>";
                 table += " <th rowspan=\"2\">体重</th>";
                 table += " <th rowspan=\"2\">身高</th>";
                 table += " <th rowspan=\"2\">舌照特征</th>";
                 table += " <th rowspan=\"2\" width=200>辨证或辨病</th>";
                 table += " <th rowspan=\"2\" width=200>药方</th>";
                 table += "<th rowspan=\"2\">舌照</th>";
                 table += "<th rowspan=\"2\">查找相似病历</th>";
                 table += "<tr><th>问题</th><th>答案</th></tr>";
                 // var keyword = '{{keyword}}';
                 //循环生成表格的每一行


                 var sex_dict = {'0':'男','1':'女'};
                 for (var i = 0; i < text_usr_dict.length; i++) {
                     //对问诊单部分的数据进行处理--方便左右两边显示

                     //问诊单问题
                     var inqueryDictQuestion = inquirySheet(text_usr_dict[i]['inquiry_sheet']);

                     var condition_report = text_usr_dict[i]['report'];
                     console.log(condition_report);

                     // 舌照特征映射,只显示异常，没有显示null，全部正常显示正常
                     var tongue_string_abormal = "";
                     var tongue_string = text_usr_dict[i]['tongue_description'];

                     if(tongue_string !== "NULL"){
                         var tongue_split = tongue_string.split(',');
                         for (var t = 0; t < tongue_split.length; t++) {
                             if(tongue_split[t].indexOf('正常') === -1){
                                 tongue_string_abormal += tongue_split[t] + '\n';
                             }
                         }
                         if (tongue_string_abormal === ''){
                            tongue_string_abormal = '正常';
                         }
                         else {
                             tongue_string_abormal = tongue_string_abormal.replace(/\n/g,'<br>');

                         }
                     }
                     else {
                         tongue_string_abormal = "NULL" ;
                     }



                     var keys = "";
                     if (inqueryDictQuestion !== null) {
                         for (var key in inqueryDictQuestion) {
                             keys += key + '\n';
                         }
                     }
                     keys = keys.replace(/\n/g, '<br>');
                     console.log(keys);
                     //相似患者问诊单答案
                     var similaryAnswer = "";
                     if (inqueryDictQuestion !== null) {
                         for (var key2 in inqueryDictQuestion) {
                             similaryAnswer += inqueryDictQuestion[key2] + '\n';
                         }
                     }
                     //将原始患者数据与相似患者数据进行对比，将相同的答案用红色标出
                     var similaryAnswer2 = similaryAnswer.split('\n');

                     //将问诊单问题和答案都进行换行显示--为了好看
                     similaryAnswer = similaryAnswer2.join('\n');
                     similaryAnswer = similaryAnswer.replace(/\n/g, '<br>');

                     var diagnosis_string = text_usr_dict[i]['diagnosis'];
                     if ( diagnosis_string !== 'NULL') {
                         diagnosis_string = diagnosis_string.replace('辨证或辨病：','');
                     }

                     var word = keyword.split(' ');
                     for (var j = 0; j < word.length; j++) {
                          if (condition_report &&  condition_report.indexOf(word[j]) !== -1 ) {
                              var reg = new RegExp(word[j], "g");
                              condition_report = condition_report.replace(reg, "<font color='red'>" + word[j] + '</font>');
                          }
                          if (similaryAnswer &&  similaryAnswer.indexOf(word[j]) !== -1 ) {
                              var regs = new RegExp(word[j], "g");
                              similaryAnswer = similaryAnswer.replace(regs, "<font color='red'>" + word[j] + '</font>');

                          }
                          // if (keys &&  keys.indexOf(word[j]) !== -1 ) {
                          //         var regk = new RegExp(word[j], "g");
                          //         keys = keys.replace(regk, "<font color='red'>" + word[j] + '</font>');
                          // }
                          if (diagnosis_string &&  diagnosis_string.indexOf(word[j]) !== -1 ) {
                                  var regd = new RegExp(word[j], "g");
                                  diagnosis_string = diagnosis_string.replace(regd, "<font color='red'>" + word[j] + '</font>');
                          }
                     }
                 var herbs_string = 'NULL';
                 if (text_usr_dict[i]['herbs'] !== 'NULL') {
                     herbs_string = text_usr_dict[i]['herbs'].replace(/,/g, '<br>');
                 }

                 tongue_url = "{{ url_for('static', filename= 'js/1.jpg') }}";
                     console.log("************************");
                     console.log(text_usr_dict[i]);
                 var html_img = "<img src="+tongue_url+" width='500' />";
                     //表格的每一行
                     table += "<tr><td>" + text_usr_dict[i].id + "</td>";
                     table += "<td>" + condition_report + "</td>";
                     table += "<td  class='tableShow'>" + keys + "</td>";  //问题
                     table += "<td class='tableShow'>" + similaryAnswer + "</td>";  //相似病人答案
                     table += "<td>" + sex_dict[text_usr_dict[i]['sex']] + "</td>";
                     table += "<td>" + text_usr_dict[i]['age'] + "</td>";
                     table += "<td>" + text_usr_dict[i]['weight'] +'kg' + "</td>";
                     table += "<td>" + text_usr_dict[i]['height'] +'cm' + "</td>";
                     table += "<td>" + tongue_string_abormal + "</td>";
                     table += "<td>" + diagnosis_string + "</td>";
                     table += "<td>" + herbs_string + "</td>";
                     table += "<td><li ><a href='http://192.168.0.139:8899/static/0/"+text_usr_dict[i].tongue_picture+".jpg'>查看</a></li></td>";
                     // table += "<td><li ><a href='http://192.168.0.139:8899/static/0/inquiry-000a1222cc71fbfe75f3e9500bba25ac_20180718162707262!961!1280.jpg'>查看</a></li></td>";

                     // table += "<td><a href='' onclick='original_fun()'>舌照" + text_usr_dict[i].id + "</a></td>"; //超链接，查图
                     // table+= "<td><li class='{% if sort == 0 %} active{% endif %}'><a href='{{url_for('show',bt = "+text_usr_dict[i].id+")}}'>开始匹配</a></li></td>" +"</tr>";
                     table += '<td><li ><a href=' + 'show1?bt=' + text_usr_dict[i].id + '>开始匹配</a></li></td></tr>'
                 }
                 table += "</table>";
                 $('#container').html(table);
             }

        })
    });


</script>
</body>



{% endblock %}

